function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

var searchobj;
var topSearchSize = 7;
var grid;
var hasArchiveItems = new Array();
var advancedQuery = {};
hasArchiveItems.push({
  text: $.i18n("govdoc.list.hasArchive.yes"),
  value: '1'
}); // 是

hasArchiveItems.push({
  text: $.i18n("govdoc.list.hasArchive.no"),
  value: '0'
}); // 否

var page_types = {
  'draft': 'draft',
  'sent': 'sent',
  'pending': 'pending',
  'finish': 'finish'
};
/**
 * 加载页面布局
 */

function loadUE() {
  new MxtLayout({
    'id': 'layout',
    'northArea': {
      'id': 'north',
      'height': 40,
      'sprit': false,
      'border': false
    },
    'centerArea': {
      'id': 'center',
      'border': false,
      'minHeight': 20
    }
  });
  /**
   * 搜索框top
   */

  if ($.browser.msie && $.browser.version == '6.0') {
    topSearchSize = 10;
  }

  if ($("#gaojiQuery").size() > 0) {
    $("#gaojiQuery").css("top", topSearchSize);
  }
}
/**
 * 编辑
 */


function doEdit(menuId, row) {
  var rows = typeof row === "undefined" ? grid.grid.getSelectRows() : [row];
  var count = rows.length;

  if (count == 0) {
    // 请选择要编辑的事项
    $.alert($.i18n('govdoc.grid.alert.selectEdit'));
    return;
  }

  if (count > 1) {
    // 只能选择一项事项进行编辑
    $.alert($.i18n('collaboration.grid.alert.selectOneEdit'));
    return;
  }

  if (count == 1) {
    var obj = rows[0];
    var affairId = obj.affairId;
    var summaryId = obj.summaryId;
    var subState = obj.affairSubState;
    var govdocType = obj.govdocType; // govdocType 0：老公文， 1：发文，2：收文，3：签报，4：交换

    var subApp = obj.affairSubApp; // subApp 0：老公文， 1：发文，2：收文，3：签报，4：交换 , 19：老公文发文 ，20：老公文收文，21：老公文签报

    var subObjectId = obj.affairSubObjectId;
    var isSend = subApp == 1 || subApp == 19;
    var isRec = subApp == 2 || subApp == 20;
    var isSign = subApp == 3 || subApp == 21;

    if (isSend && obj.isQuickSend) {
      if (!$.ctx.resources.contains('F20_fawenNewQuickSend') && !$.ctx.resources.contains('F20_govdocMC4806761506182939350')) {
        if (typeof edocQuickSendRoleFrromBack == 'undefined' || edocQuickSendRoleFrromBack != "true") {
          $.alert($.i18n('govdoc.new.noAuth.quickSend'));
          return false;
        }
      }
    } else if (!$.ctx.resources.contains('F20_newSend') && !$.ctx.resources.contains('F20_govdocMC-8544674753297104169') && isSend) {
      if (typeof sendEdocRoleFromBack == 'undefined' || sendEdocRoleFromBack != "true") {
        // 没有发文拟文权限！
        $.alert($.i18n('govdoc.new.noAuth.send'));
        return false;
      }
    } else if (!$.ctx.resources.contains('F20_newDengji') && !$.ctx.resources.contains('F20_govdocMC-4269480178511557817') && isRec) {
      if (typeof recEdocRole == 'undefined' || recEdocRole != "true") {
        // 没有收文登记权限！
        $.alert($.i18n('govdoc.new.noAuth.rec'));
        return false;
      }
    } else if (!$.ctx.resources.contains('F20_newSign') && !$.ctx.resources.contains('F20_govdocMC-2894104827059616652') && isSign) {
      if (typeof signEdocRole == 'undefined' || signEdocRole != "true") {
        // 没有签报拟文权限！
        $.alert($.i18n('govdoc.new.noAuth.sign'));
        return false;
      }
    }

    if (govdocType != 0) {
      //新公文
      var url = _ctxPath + "/govdoc/govdoc.do?method=newGovdoc&summaryId=" + summaryId + "&affairId=" + affairId + "&from=waitSend&sub_app=" + govdocType;

      if (obj.isQuickSend == true) {
        url += "&isQuickSend=true";
      }

      openCtpWindow({
        'url': url,
        'id': affairId
      });
    } else {
      //老公文
      var _url2 = getOldUrl("edit", openFrom, subApp, summaryId, affairId, subObjectId, "", subState);

      if (!_url2) {
        return;
      }

      window.location.href = _url2;
    }
  }
}
/**
 * 撤销
 */


function doCancel(event, rowDatas) {
  var rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;

  if (rows.length === 0) {
    //请选择需要撤销的公文！
    $.alert($.i18n('govdoc.listSent.selectRevokeSyn'));
    enabledToolbar();
    return;
  }

  if (rows.length > 1) {
    //只能选择一条记录!
    $.alert($.i18n('collaboration.listSent.selectOneData'));
    enabledToolbar();
    return;
  }

  if (checkGovdocDeviceSecret(rows[0])) {
    return;
  }

  var selRow = rows[0];
  var isOldEdoc = selRow.affairSubApp > 4;

  if (isOldEdoc == true) {
    cancelOldEdoc(selRow);
  } else {
    var affairId = selRow.affairId; //已发列表判断是否有撤销流程权限

    if (typeof govdocAManager != "undefined") {
      var ajaxManager = new govdocAManager();
      var r = ajaxManager.getRightByAction(affairId, "Cancel"); // 后台返回空字符串表示有权限

      if (r === '') {
        cancelCallBack(rows);
      } else {
        alert(r);
      }
    } else {
      cancelCallBack(rows);
    }
  }
}

function cancelCallBack(rows) {
  var exchange = new govdocExchangeManager();
  var result = "";

  if (result == "has") {
    var win = new MxtMsgBox({
      'type': 0,
      'msg': $.i18n('govdoc.document.cancel.recommend'),
      ok_fn: function ok_fn() {
        cancelDate(rows);
      }
    });
  } else {
    cancelDate(rows);
  }
} //撤销老公文


function cancelOldEdoc(rowData) {
  disabledToolbar();
  var requestCaller = new XMLHttpRequestCaller(this, "edocManager", "checkIsCanBeRepealed", false);
  requestCaller.addParameter(1, 'String', rowData.affairObjectId);
  var ret = requestCaller.serviceRequest();

  if ("Y" != ret) {
    alert(ret);
    enabledToolbar();
    return;
  }

  var requestCaller = new XMLHttpRequestCaller(this, "WFAjax", "lockWorkflow", false);
  requestCaller.addParameter(1, "String", rowData.processId);
  requestCaller.addParameter(2, "String", $.ctx.CurrentUser.id);
  requestCaller.addParameter(3, "int", 12);
  var ret = requestCaller.serviceRequest();

  if (ret[0] == "false") {
    alert(re[1]);
    enabledToolbar();
    return;
  }

  if (!executeWorkflowBeforeEvent("BeforeCancel", rowData.affairObjectId, rowData.affairId, rowData.processId, rowData.processId, "", "", "")) {
    enabledToolbar();
    return;
  } //撤销流程


  var dialog = $.dialog({
    url: _ctxPath + "/workflowmanage/workflowmanage.do?method=showRepealCommentDialog&affairId=" + rowData.affairId,
    width: 450,
    height: 240,
    bottomHTML: '<span></span>',
    title: $.i18n('common.toolbar.repeal.label'),
    //撤销流程
    targetWindow: getCtpTop(),
    buttons: [{
      text: $.i18n('common.button.ok.label'),
      //确定
      btnType: 1,
      handler: function handler() {
        enabledToolbar();
        var returnValue = dialog.getReturnValue();

        if (!returnValue) {
          return;
        }

        var requestCaller = new XMLHttpRequestCaller(this, "ajaxEdocManager", "cancelSummaryOldEdoc", false);
        requestCaller.addParameter(1, 'String', rowData.affairId);
        requestCaller.addParameter(2, 'String', returnValue[0]); //repealComment 撤销附言

        requestCaller.addParameter(3, 'int', returnValue[1]); //isWFTrace 是否追溯流程 1是，0否

        var msg = requestCaller.serviceRequest();

        if (msg == null || msg == "") {
          $("#summary").attr("src", "");
          $(".slideDownBtn").trigger("click");
          $("#listSent").ajaxgridLoad();
        } else {
          $.alert(msg);
        }

        dialog.close(); //撤销后关闭，子页面

        try {
          closeOpenMultyWindow(rowData.affairId);
        } catch (e) {}

        ;
      }
    }, {
      text: $.i18n('common.button.cancel.label'),
      //取消
      handler: function handler() {
        enabledToolbar();
        releaseWorkflow(undefined, rowData, 12);
        dialog.close();
      }
    }],
    closeParam: {
      show: true,
      handler: function handler() {
        enabledToolbar();
        releaseWorkflow(undefined, rowData, 12);
        dialog.close();
      }
    }
  });
}
/**
 * 释放流程
 * @param rowData
 */


function releaseWorkflow(event, rowData, action) {
  var requestCaller = new XMLHttpRequestCaller(this, "WFAjax", "releaseWorkflow", false);
  requestCaller.addParameter(1, "String", rowData.processId);
  requestCaller.addParameter(2, "String", $.ctx.CurrentUser.id);
  requestCaller.addParameter(3, "int", action);
  requestCaller.serviceRequest();
}
/**
 * 删除
 */


function doDelete(pageType, tableId, from, inputRows) {
  deleteItems(pageType, grid, tableId, from, inputRows);
}
/**
 * 取回
 */


function doTakeBack(event, rowDatas) {
  //js事件接口
  var sendDevelop = $.ctp.trigger('beforeDoneTakeBack');

  if (!sendDevelop) {
    return;
  }

  var rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;

  if (rows.length === 0) {
    //请选择要取回的协同!
    $.alert($.i18n('govdoc.listDone.selectBack'));
    return;
  }

  if (rows.length > 1) {
    //只能选择一项协同进行取回!
    $.alert($.i18n('govdoc.listDone.selectOneBack'));
    return;
  }

  if (checkGovdocDeviceSecret(rows[0])) {
    return;
  }

  var isOldEdoc = rows[0].affairSubApp > 4;

  if (isOldEdoc == true) {
    doTakeBackOldEdoc(undefined, rows);
  } else {
    doTakeBackNewEdoc(undefined, rows);
  }
}
/**
 * 取回
 */


var clickCount = 0; //取回重复点击计数

function doTakeBackOldEdoc(event, inputRows) {
  clickCount++;

  if (clickCount > 1) {
    //重复点击给出提示
    var msg = v3x.getMessage("edocLang.edoc_click_alert");
    alert(msg);
    clickCount = 0;
    return;
  }

  var rows = typeof inputRows === "undefined" ? grid.grid.getSelectRows() : inputRows;

  if (rows[0].summaryState == 7) {
    var str = $.i18n("edocLang.edoc_flow_Retrieve");
    $.alert(str);
    clickCount = 0;
    return;
  }

  var requestCaller = new XMLHttpRequestCaller(this, "ajaxEdocManager", "canTakeBack", false);
  requestCaller.addParameter(1, "String", "edoc");
  requestCaller.addParameter(2, 'String', rows[0].processId);
  requestCaller.addParameter(3, 'String', rows[0].affairActivityId);
  requestCaller.addParameter(4, 'String', rows[0].affairSubObjectId);
  requestCaller.addParameter(5, 'String', rows[0].affairId);
  var state = requestCaller.serviceRequest();

  if (state == "-1") {
    var _str = v3x.getMessage("edocLang.edoc_flow_Retrieve0");

    alert(_str);
    clickCount = 0;
    return;
  } else if (state == "1") {
    var _str2 = v3x.getMessage("edocLang.edoc_flow_Retrieve1");

    alert(_str2);
    clickCount = 0;
    return;
  } else if (state == "2") {
    var _str3 = v3x.getMessage("edocLang.edoc_flow_Retrieve2");

    alert(_str3);
    clickCount = 0;
    return;
  } else if (state == "3") {
    var _str4 = v3x.getMessage("edocLang.edoc_flow_Retrieve3");

    alert(_str4);
    clickCount = 0;
    return;
  } else if (state == "4") {
    var _str5 = v3x.getMessage("edocLang.edoc_flow_Retrieve4");

    alert(_str5);
    clickCount = 0;
    return;
  } else if (state == "5") {
    var _str6 = v3x.getMessage("edocLang.edoc_flow_Retrieve5");

    alert(_str6);
    clickCount = 0;
    return;
  } else if (state == "6") {
    var _str7 = v3x.getMessage("edocLang.edoc_flow_Retrieve6");

    alert(_str7);
    clickCount = 0;
    return;
  } else if (state == "7") {
    var _str8 = v3x.getMessage("edocLang.edoc_flow_Retrieve7");

    alert(_str8);
    clickCount = 0;
    return;
  } else if (state == "8") {
    var _str9 = v3x.getMessage("edocLang.edoc_flow_Retrieve8");

    alert(_str9);
    clickCount = 0;
    return;
  } else if (state == "11") {
    var _str10 = v3x.getMessage("edocLang.edoc_cancel_takeback");

    alert(_str10);
    document.location.reload();
    clickCount = 0;
    return;
  } else if (state == "12") {
    var _str11 = v3x.getMessage("edocLang.edoc_stepback_takeback");

    alert(_str11);
    document.location.reload();
    clickCount = 0;
    return;
  } else if (state == "22") {
    var _str12 = v3x.getMessage("edocLang.edoc_flow_Retrieve22");

    alert(_str12);
    document.location.reload();
    clickCount = 0;
    return;
  }

  if (rows[0].affairNodePolicy == "zhihui" || rows[0].affairNodePolicy == "inform") {
    alert(v3x.getMessage("collaborationLang.collaboration_zhihuiTakeBackItem"));
    clickCount = 0;
    return;
  }

  var summaryId = rows[0].affairObjectId; //判断是否已经被发送

  var requestCaller = new XMLHttpRequestCaller(this, "edocManager", "isBeSended", false);
  requestCaller.addParameter(1, "Long", summaryId);
  var rs = requestCaller.serviceRequest();

  if (rs == 'true') {
    var msg = v3x.getMessage("edocLang.edoc_state_end_takeback_sendalert") + $.i18n("edoc.symbol.opening.chevron") + rows[0].affairSubject + $.i18n("edoc.symbol.closing.chevron") + "\n";
    alert(msg);
    clickCount = 0;
    return false;
  } //取回加锁


  var requestCaller = new XMLHttpRequestCaller(this, "WFAjax", "lockWorkflow", false);
  requestCaller.addParameter(1, "String", rows[0].processId);
  requestCaller.addParameter(2, "String", $.ctx.CurrentUser.id);
  requestCaller.addParameter(3, "int", 13); //取回加锁

  var re = requestCaller.serviceRequest();

  if (re[0] == "false") {
    var requestCaller = new XMLHttpRequestCaller(this, "WFAjax", "releaseWorkflow", false);
    requestCaller.addParameter(1, "String", rows[0].processId);
    requestCaller.addParameter(2, "String", $.ctx.CurrentUser.id);
    requestCaller.addParameter(3, "int", 13);
    requestCaller.serviceRequest();
    alert(re[1]);
    clickCount = 0;
    return;
  }

  if (!executeWorkflowBeforeEvent("BeforeTakeBack", summaryId, rows[0].affairId, rows[0].processId, rows[0].processId, rows[0].affairActivityId, "", "")) {
    clickCount = 0;
    var requestCaller = new XMLHttpRequestCaller(this, "WFAjax", "releaseWorkflow", false);
    requestCaller.addParameter(1, "String", rows[0].processId);
    requestCaller.addParameter(2, "String", $.ctx.CurrentUser.id);
    requestCaller.addParameter(3, "int", 13);
    requestCaller.serviceRequest();
    return;
  }

  if (window.confirm(v3x.getMessage("edocLang.edoc_confirmTakeBackItem"))) {
    clickCount = 0; //重复点击计数归零

    var requestCaller = new XMLHttpRequestCaller(this, "ajaxEdocManager", "takeBackForOldEdoc", false);
    requestCaller.addParameter(1, 'String', rows[0].affairId);
    requestCaller.addParameter(2, 'String', rows[0].affairObjectId);
    var ret = requestCaller.serviceRequest();

    if (ret != "") {
      alert(ret);
    }

    $("#summary").attr("src", "");
    $(".slideDownBtn").trigger("click");

    if ($("#tableContent").length > 0) {
      $("#tableContent").ajaxgridLoad();
    } else {
      $("#listDone").ajaxgridLoad();
    }
  } else {
    clickCount = 0; //重复点击计数归零

    var requestCaller = new XMLHttpRequestCaller(this, "WFAjax", "releaseWorkflow", false);
    requestCaller.addParameter(1, "String", rows[0].processId);
    requestCaller.addParameter(2, "String", $.ctx.CurrentUser.id);
    requestCaller.addParameter(3, "int", 13);
    requestCaller.serviceRequest();
  }
}
/**
 * 取回
 */


function doTakeBackNewEdoc(event, rowDatas) {
  var rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;
  var affairId = rows[0].affairId;
  var workitemId = rows[0].affairSubObjectId;
  var activityId = rows[0].affairActivityId;
  var ajaxManager = new govdocAManager();
  var affairTemp = ajaxManager.getAffairById(affairId);

  if (affairTemp == null || affairTemp.state != 4) {
    $.alert($.i18n("govdoc.can.not.takeback"));
    return;
  }

  if ($("#deduplication").is(":checked")) {
    //由于同一流程只显示一条,这里需要取最后一条affair
    var affair = ajaxManager.getLastDoneAffair(rows[0].summaryId, rows[0].affairMemberId);
    affairId = affair.id;
    workitemId = affair.subObjectId;
    activityId = affair.activityId;
  }

  var result = ajaxManager.hasDistributed(rows[0].summaryId);

  if (result) {
    $.alert($.i18n("govdoc.distribute.canNot.retrival"));
    return;
  }

  if (!isAffairValid(affairId)) {
    $("#listDone").ajaxgridLoad();
    return;
  }
  /**
   * 是否允许取回
   * 返回值是一个js对象，有以下属性
   * canTakeBack 是否允许取回
   * state:
   *  -1表示程序或数据发生异常,不可以取回
   *  0表示正常状态,可以取回
   *  1表示当前流程已经结束,不可以取回
   *  2表示后面节点任务事项已处理完成,不可以取回
   *  3表示当前节点触发的子流程已经结束,不可以取回
   *  4表示当前节点触发的子流程中已核定通过,不可以取回
   *  5表示当前节点是知会节点,不可以取回
   *  6表示当前节点为核定节点,不可以取回
   *  7表示当前节点为封发节点，不可以取回
   */


  var workitemId = workitemId;
  var processId = rows[0].processId;
  var caseId = rows[0].caseId;
  var appName = "collaboration";
  var nodeId = activityId;
  var isForm = rows[0].bodyType == '20';
  var canTakeBackObj = canTakeBack(workitemId, processId, nodeId, null, caseId, appName, isForm, affairId);

  if (canTakeBackObj != null && !canTakeBackObj.canTakeBack || canTakeBackObj.state == "-1") {
    if (canTakeBackObj.state === "-1") {
      canTakeBackObj.state = "1";
    }

    var msg = 'collaboration.takeBackErr.' + canTakeBackObj.state + '.msg';
    $.alert($.i18n(msg));
    return;
  }

  var lockWorkflowRe = lockWorkflow(processId, $.ctx.CurrentUser.id, 13);

  if (lockWorkflowRe[0] == "false") {
    $.alert(lockWorkflowRe[1]);
    return;
  }

  if (!executeWorkflowBeforeEvent("BeforeTakeBack", rows[0].summaryId, affairId, processId, processId, nodeId, "", appName)) {
    return;
  }

  var dialog = $.dialog({
    url: _ctxPath + "/govdoc/govdoc.do?method=takeBackDialog&govdoc=1",
    width: 350,
    height: 160,
    targetWindow: getCtpTop(),
    title: $.i18n('common.system.hint.label'),
    buttons: [{
      text: $.i18n('common.button.ok.label'),
      handler: function handler() {
        var rv = dialog.getReturnValue();

        if (rv) {
          var ajaxSubmitFunc = function ajaxSubmitFunc() {
            var saveOpinion = rv != "1";
            var takeBackBean = new Object();
            takeBackBean["affairId"] = affairId;
            takeBackBean["isSaveOpinion"] = saveOpinion;
            ajaxManager.transTakeBack(takeBackBean, {
              success: function success(data) {
                var msg = data["msg"];

                if (msg == null || msg == "") {
                  $("#summary").attr("src", "");
                  $(".slideDownBtn").trigger("click");

                  if ($("#tableContent").length > 0) {
                    $("#tableContent").ajaxgridLoad();
                  } else {
                    $("#listDone").ajaxgridLoad();
                  }
                } else {
                  $.alert(msg);
                } //撤销后关闭，子页面


                try {
                  closeOpenMultyWindow(affairId);
                } catch (e) {}

                ; //打开取回的页面

                var url = _ctxPath + "/govdoc/govdoc.do?method=summary&affairId=" + affairId + "&openFrom=listPending";
                window.open(url);
              }
            });
          };

          ajaxSubmitFunc();
        }

        dialog.close();
      }
    }, {
      text: $.i18n('common.button.cancel.label'),
      handler: function handler() {
        releaseWorkflowByAction(processId, $.ctx.CurrentUser.id, 13);
        dialog.close();
      }
    }],
    closeParam: {
      show: true,
      handler: function handler() {
        releaseWorkflowByAction(processId, $.ctx.CurrentUser.id, 13);
      }
    }
  });
}
/**
 * 归档
 */


function doPigeonhole(pageType, gridI, tableId, rowDatas) {
  var v = $("#" + tableId).formobj({
    gridFilter: function gridFilter(data, row) {
      if (row != null) {
        return $("input:checkbox", row)[0].checked;
      } else {
        return true;
      }
    }
  });
  v = typeof rowDatas === "undefined" ? v : rowDatas;

  if (v.length === 0) {
    $.alert($.i18n('govdoc.edoc.alert.select'));
    return;
  }

  var ids = new Array();
  var check = false;
  var archiveSubject = '';
  var workflowSubject = '';
  var opinionSubject = '';
  var lockWorkflowRe;
  $(v).each(function (index, elem) {
    // 老公文的签收、登记、分发的公文都不能归档，其他数据允许归档
    // govdocType 0 老公文
    // affairSubApp 22 公文待交换 23 公文待签收 24 待登记公文 34 收文分发
    if (elem.govdocType == 0 && [22, 23, 24, 34].indexOf(elem.affairSubApp) > -1) {
      $.alert({
        msg: "《" + elem.subject + "》 " + $.i18n("govdoc.oldData.notArchive") + "",
        ok_fn: function ok_fn() {
          if (parent.document.getElementById('resourceDataIframe')) {
            parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
          } else if (parent.document.getElementById('mainIframe')) {
            parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          } else if (parent.parent.document.getElementById('mainIframe')) {
            parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          }
        }
      });
      check = true;
      return false;
    }

    if (elem.app == 22 || elem.app == 23 || elem.app == 24 || elem.app == 40) {
      $.alert({
        msg: "《" + elem.subject + "》 " + $.i18n("govdoc.oldData.notSupport") + "",
        ok_fn: function ok_fn() {
          var mainFrame = parent.document.getElementById('main');

          if (mainFrame) {
            mainFrame.contentWindow.location.reload(true);
          } else {
            if (parent.document.getElementById('resourceDataIframe')) {
              parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
            } else if (parent.document.getElementById('mainIframe')) {
              parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
            } else if (parent.parent.document.getElementById('mainIframe')) {
              parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
            }
          }
        }
      });
      check = true;
      return false;
    } //待办的逻辑(还需要翟峰多查询几个条件)


    if (pageType == "pending") {
      // if (elem.templeteId) {
      // 	//未办理的模板协同不允许直接归档或删除
      // 	check = true;
      // 	archiveSubject += "<br><" + elem.subject + ">";
      // }
      lockWorkflowRe = checkWorkflowLock(elem.processId, $.ctx.CurrentUser.id, 14);

      if (lockWorkflowRe[0] == "false") {
        check = true;
        workflowSubject += "<br><" + elem.subject + ">";
      } // if (!elem.canDeleteORarchive) {
      // 	//以下事项要求意见不能为空，不能直接归档或删除
      // 	check = true;
      // 	opinionSubject += "<br><" + elem.subject + ">";
      // }
      // 指定回退时不能处理


      var canSubmitWorkFlowRe = canSubmitWorkFlow(elem.workitemId);

      if (canSubmitWorkFlowRe && canSubmitWorkFlowRe[0] == "false") {
        $.alert({
          msg: canSubmitWorkFlowRe[1],
          ok_fn: function ok_fn() {
            var mainFrame = parent.document.getElementById('main');

            if (mainFrame) {
              mainFrame.contentWindow.location.reload(true);
            } else {
              if (parent.document.getElementById('resourceDataIframe')) {
                parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
              } else if (parent.document.getElementById('mainIframe')) {
                parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
              } else if (parent.parent.document.getElementById('mainIframe')) {
                parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
              }
            }
          }
        });
        check = true;
        return false;
      }
    } //列表判断是否有归档权限


    if ('govdocsent' != pageType && typeof govdocAManager != "undefined") {
      var ajaxManager = new govdocAManager();
      var r = ajaxManager.getRightByAction(elem.affairId, "Archive");

      if (r && r != true) {
        $.alert({
          msg: r,
          ok_fn: function ok_fn() {
            //公文封装菜单DOM 层级结构有变化 前面嵌套了一层
            if (typeof previewResourceId != "undefined" && previewResourceId != null && previewResourceId != "") {
              // parent.document.getElementById('main').firstChild.contentWindow.location.reload(true);
              return;
            } else {
              var mainFrame = parent.document.getElementById('main');

              if (mainFrame && mainFrame.contentWindow) {
                mainFrame.contentWindow.location.reload(true);
              } else {
                if (parent.document.getElementById('resourceDataIframe')) {
                  parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
                } else if (parent.document.getElementById('mainIframe')) {
                  parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
                } else if (parent.parent.document.getElementById('mainIframe')) {
                  parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
                }
              }
            }
          }
        });
        check = true;
        return false;
      }
    }

    ids.push(elem.affairId);
  });

  if (archiveSubject.length > 1) {
    $.alert({
      msg: $.i18n('collaboration.template.notHandle.notDeleteArchive') + "<br>" + archiveSubject,
      ok_fn: function ok_fn() {
        var mainFrame = parent.document.getElementById('main');

        if (mainFrame) {
          mainFrame.contentWindow.location.reload(true);
        } else {
          if (parent.document.getElementById('resourceDataIframe')) {
            parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
          } else if (parent.document.getElementById('mainIframe')) {
            parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          } else if (parent.parent.document.getElementById('mainIframe')) {
            parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          }
        }
      }
    });
    return;
  }

  if (workflowSubject.length > 1) {
    $.alert({
      msg: lockWorkflowRe[1] + "<br>" + workflowSubject,
      ok_fn: function ok_fn() {
        var mainFrame = parent.document.getElementById('main');

        if (mainFrame) {
          mainFrame.contentWindow.location.reload(true);
        } else {
          if (parent.document.getElementById('resourceDataIframe')) {
            parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
          } else if (parent.document.getElementById('mainIframe')) {
            parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          } else if (parent.parent.document.getElementById('mainIframe')) {
            parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          }
        }
      }
    });
    return;
  }

  if (opinionSubject.length > 1) {
    $.alert({
      msg: $.i18n('collaboration.template.notDeleteArchive.nullOpinion') + "<br>" + opinionSubject,
      ok_fn: function ok_fn() {
        var mainFrame = parent.document.getElementById('main');

        if (mainFrame) {
          mainFrame.contentWindow.location.reload(true);
        } else {
          if (parent.document.getElementById('resourceDataIframe')) {
            parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
          } else if (parent.document.getElementById('mainIframe')) {
            parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          } else if (parent.parent.document.getElementById('mainIframe')) {
            parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
          }
        }
      }
    });
    return;
  }

  if (check) {
    return;
  }

  var callerResponder = new CallerResponder();

  callerResponder.success = function (jsonObj) {
    if (jsonObj != "") {
      $.alert({
        msg: escapeStringToHTML(jsonObj),
        ok_fn: function ok_fn() {
          var mainFrame = parent.document.getElementById('main');

          if (mainFrame) {
            mainFrame.contentWindow.location.reload(true);
          } else {
            if (parent.document.getElementById('resourceDataIframe')) {
              parent.document.getElementById('resourceDataIframe').contentWindow.location.reload(true);
            } else if (parent.document.getElementById('mainIframe')) {
              parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
            } else if (parent.parent.document.getElementById('mainIframe')) {
              parent.parent.document.getElementById('mainIframe').contentWindow.location.reload(true);
            }
          }
        }
      });
    } else {
      doPigeonholeCheck(ids, pageType, tableId, gridI);
    }
  };

  var ajaxManager = new govdocAManager();
  ajaxManager.getPigeonholeRight(ids, callerResponder);
}

function doPigeonholeCheck(ids, pageType, tableId, gridI) {
  doPigeonholeCheckCallbackIds = ids;
  doPigeonholeCheckCallbackPageType = pageType;
  doPigeonholeCheckCallbackTableId = tableId;
  doPigeonholeCheckCallbackGrid = gridI;
  var result = pigeonhole(400, null, null, null, pageType, "doPigeonholeCheckCallback");
}
/**
 * doPigeonholeCheck归档回调
 */


function doPigeonholeCheckCallback(result) {
  if (result && result != "cancel") {
    var folder = result.split(",");
    var callerResponder = new CallerResponder();

    callerResponder.success = function (jsonObj) {
      doPigeonholeCol(doPigeonholeCheckCallbackIds, folder, doPigeonholeCheckCallbackPageType, doPigeonholeCheckCallbackTableId, doPigeonholeCheckCallbackGrid);
    };

    var ajaxManager = new govdocAManager();
    ajaxManager.getIsSamePigeonhole(doPigeonholeCheckCallbackIds, folder[0], callerResponder);
  }
}

function doPigeonholeCol(ids, folder, pageType, tableId, grid) {
  var ajaxManager = new govdocAManager(); //增加判断当前文档是否已经归档了

  var res = ajaxManager.checkPigeonhole(ids, folder[0], pageType);

  if (res && res.length > 0) {
    alert(res);
    return;
  } // 开始归档


  var hasError = false;

  for (var i = 0; i < ids.length; i++) {
    var result = ajaxManager.transPigeonhole(ids[i], folder[0], pageType);

    if (result != '') {
      hasError = true;
      break;
    }
  } //归档成功


  if (!hasError) {
    // todo 归档调用接口
    var rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;

    if (rows != null && rows.length > 0) {
      for (var j = 0; j < rows.length; j++) {
        var processId = rows[j].processId;
        var subject = rows[j].subject;
        var data = {
          "processId": processId,
          "activityId": 0,
          "actionId": -35,
          "appActionId": 0,
          "userId": "",
          "attType": 0,
          "attName": "",
          "attId": "",
          "oldSecretLevel": "",
          "newSecretLevel": "",
          "processName": subject,
          "folderName": folder[1],
          "category": 4,
          "fileId": "",
          "includeAppLog": true
        };
        jQuery.ajax({
          async: false,
          method: 'POST',
          url: _ctxPath + '/rest/workflow/log/processDoLog',
          dataType: 'json',
          contentType: 'application/json;charset=UTF-8',
          data: JSON.stringify(data)
        });
      }
    }

    $.infor($.i18n('collaboration.grid.alert.archiveSuccess'));
  } //删除重复的文档


  ajaxManager.transPigeonholeDeleteStepBackDoc(ids, folder[0]); //刷新列表

  var url = window.location.search;
  var o = new Object();
  setParamsToObject(o, url);

  if (url.indexOf("showConfigData") > -1) {
    //公文应用定制toolbar操作归档后刷新页面
    $("#" + tableId).ajaxgridLoad();
  } else {
    //最后归档成功后调用
    //根据查询条件刷新列表，getConditionObj()方法在各页面的js里都有定义（例已办结页面listDone.jsp对应的listDone.js内就有此方法）
    $.extend(o, getConditionObj());
    $("#" + tableId).ajaxgridLoad(o);

    if ('govdocsent' != pageType) {
      grid.grid.resizeGridUpDown("down");

      if (tableId === "listPending") {
        $('#summary').attr("src", _ctxPath + "/collaboration/collaboration.do?method=listDesc&type=listPending&size=" + grid.p.total);
      } //归档后关闭子页面打开的协同


      for (var i = 0; i < ids.length; i++) {
        var affairId = ids[i];

        try {
          closeOpenMultyWindow(affairId);
        } catch (e) {}
      }
    }
  }
}
/**
 * 转发文
 */


function doForward(event, rowDatas) {
  //1.验证是否开启了【转发文】策略
  var rows = typeof rowDatas === 'undefined' ? grid.grid.getSelectRows() : rowDatas;

  if (rows.length != 1) {
    //alert("选择一条数据");
    $.alert($.i18n('govdoc.edoc.listDone.selectOneData'));
    return;
  }

  if (checkGovdocDeviceSecret(rows[0])) {
    return;
  }

  var govdocType = rows[0].govdocType; //老公文 屏蔽该功能

  if (rows[0].affairSubApp > 4) {
    $.alert("《" + rows[0].subject + "》 " + $.i18n('govdoc.oldData.document') + $.i18n('edoc.alert.oldEdocSummary.noFunction'));
    return;
  }

  if (govdocType != 2) {
    //alert("不能选择发文流程/交换流程");
    $.alert($.i18n('govdoc.edoc.listDone.dontProcess'));
    return;
  }

  if ("1" != sendedocRole) {
    $.alert($.i18n("govdoc.send.right.notHave"));
    return;
  } //判断该公文在当前节点是否有转发文操作


  var canTrans = callBackendMethod("secretAjaxManager", "canTransSecretLevelWithApp", rows[0].summaryId, 3, 3);

  if (canTrans == false) {
    $.alert($.i18n('collaboration.grid.alert.noTransSecretData'));
    return;
  }

  $.ajax({
    type: 'post',
    data: {
      orgAccountId: rows[0].orgAccountId,
      govdocType: rows[0].govdocType,
      affairId: rows[0].affairId
    },
    url: _ctxPath + '/govdoc/govdoc.do?method=isZhuanFawen',
    dataType: 'json',
    success: function success(data) {
      if (data == '1') {
        var onlyQuickSend = "";

        if (!$.ctx.resources.contains('F20_newSend') && $.ctx.resources.contains('F20_fawenNewQuickSend')) {
          onlyQuickSend = "true";
        }

        var forwardAffairId = rows[0].affairId;

        if (zhuanfawen != "no") {
          //开启了转发文默认设置
          var url = _ctxPath + "/govdoc/govdoc.do?method=newGovdoc&app=4&sub_app=1&forwardAffairId=" + forwardAffairId + "&transParams=" + zhuanfawen + "&isQuickSend=" + onlyQuickSend + "&from=recToSend";
          var title = $.i18n("govdoc.document.new");
          openGovdocDialog(url, escapeStringToHTML(title));
        } else {
          var dialog = $.dialog({
            url: _ctxPath + "/govdoc/govdoc.do?method=forwordOption",
            width: 300,
            height: 195,
            title: $.i18n('govdoc.button.forwardText.label'),
            targetWindow: getCtpTop(),
            buttons: [{
              text: $.i18n('common.button.ok.label'),
              handler: function handler() {
                var rv = dialog.getReturnValue(); // 转发文时如果用户选择了【正文作为新公文的正文或附件】，则需要校验是否进行了打印控制

                if (rows[0].govdocType == "2" && rv && (rv.startsWith("0") || rv.startsWith("1"))) {
                  if (checkSummaryPrintControl(rows[0].summaryId)) {
                    $.alert($.i18n('govdoc.print.control.prompt1')); // 该正文打印受控制，不支持正文作为新公文的正文或附件进行转发文

                    return;
                  }
                }

                dialog.close();
                var url = _ctxPath + "/govdoc/govdoc.do?method=newGovdoc&app=4&sub_app=1&forwardAffairId=" + forwardAffairId + "&transParams=" + rv + "&isQuickSend=" + onlyQuickSend + "&from=recToSend";
                var title = $.i18n("govdoc.document.new");
                openGovdocDialog(url, escapeStringToHTML(title));
              }
            }, {
              text: $.i18n('common.button.close.label'),
              handler: function handler() {
                dialog.close();
              }
            }]
          });
        }
      } else {
        $.alert($.i18n('govdoc.permission.forward.notHave'));
        return;
      }
    },
    error: function error() {
      alert("error");
    }
  });
}
/**
 * 转协同
 */


function doForwardCol(event, rowDatas) {
  var rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;

  if (rows.length != 1) {
    //alert("选择一条数据");
    $.alert($.i18n('govdoc.edoc.listDone.selectOneData'));
    return;
  }

  if (checkGovdocDeviceSecret(rows[0])) {
    return;
  }

  var govdocType = rows[0].govdocType;
  var affairSubject = rows[0].affairSubject || rows[0].subject || rows[0].elementSubject; //老公文 屏蔽该功能

  if (rows[0].affairSubApp > 4) {
    $.alert("《" + rows[0].subject + "》 " + $.i18n('govdoc.oldData.document') + $.i18n('edoc.alert.oldEdocSummary.noFunction'));
    return;
  } //涉密应用检查 see com.seeyon.ctp.secret.manager.AppSecretLevelEnum


  var canTrans = callBackendMethod("secretAjaxManager", "canTransSecretLevelWithApp", rows[0].summaryId, 3, 1);

  if (canTrans == false) {
    $.alert($.i18n('govdoc.grid.alert.noTransSecretData'));
    return;
  } //判断该公文在当前节点是否有转事务操作


  var ajaxManager = new govdocAManager();
  var operation = "Zhuanshiwu";
  var data = ajaxManager.hasTransCollStrategy(rows[0].orgAccountId, rows[0].govdocType, rows[0].affairId, operation);

  if (data == operation) {
    collaborationApi.newColl({
      manual: "true",
      //后台进行数据设置
      from: 'govdoc',
      handlerName: 'govdoc',
      sourceId: rows[0].affairId,
      ext: ''
    });
  } else {
    $.alert($.i18n("govdoc.official.document") + affairSubject + $.i18n("govdoc.transfer.business.notallowed"));
    return;
  }
}
/**
 * 同一流程只显示一条
 */


function doDeduplication() {
  var o = getConditionObj();

  if (Object.keys(advancedQuery).length > 0) {
    var result = Object.assign(advancedQuery, o);
    o = result;
  }

  searchByCondition(o);
}
/** *********************************** 公文列表数据高级查询 ************************************** */


function openComQueryDialog() {
  var _url = edocListURL + "?method=openComQueryDialog&listType=" + listType + "&govdocType=" + govdocType;

  if (typeof showHandover != "undefined") {
    _url += "&showHandover=" + showHandover;
  }

  if (typeof configId != "undefined") {
    _url += "&configId=" + configId;
  }

  searchobj.g.clearCondition();
  advancedQuery = {};
  var queryDialog = $.dialog({
    url: _url,
    width: 400,
    height: 420,
    title: $.i18n('govdoc.advanced.search'),
    //高级查询
    id: 'queryDialog',
    transParams: [window],
    targetWindow: getCtpTop(),
    closeParam: {
      show: true,
      autoClose: false,
      handler: function handler() {
        queryDialog.close({
          isFormItem: true
        });
      }
    },
    buttons: [{
      id: "okButton",
      text: $.i18n("common.button.ok.label"),
      handler: function handler() {
        advancedQuery = queryDialog.getReturnValue({
          type: 1
        });

        if (advancedQuery) {
          queryDialog.close();

          if (templateIds) {
            advancedQuery.templateIds = templateIds;
          } //同一流程只显示最后一条


          advancedQuery.deduplication = "true";
          var isDedupCheck = $("#deduplication").attr("checked");

          if (!isDedupCheck) {
            advancedQuery.deduplication = "false";
          }

          searchByCondition(advancedQuery);

          if (typeof parent.toAllTabMenu != "undefined") {
            parent.toAllTabMenu(0);
          }
        }
      }
    }, {
      id: "cancelButton",
      text: $.i18n('govdoc.reset'),
      handler: function handler() {
        queryDialog.getReturnValue({
          type: 2
        });
      }
    }]
  });
}

function pageReload() {
  window.location.reload();
} //置灰ToolBar


function disabledToolbar() {
  toolbar.disabled("transmit"); //归档

  if (isShowPigeonhole()) {
    toolbar.disabled("pigeonhole");
  }

  toolbar.disabled("cancelWorkFlow");
  toolbar.disabled("editWorkFlow");
  toolbar.disabled("resend");
  toolbar.disabled("delete");
  toolbar.disabled("relationAuthority");
}

function enabledToolbar() {
  toolbar.enabled("transmit"); //归档

  if (isShowPigeonhole()) {
    toolbar.enabled("pigeonhole");
  }

  toolbar.enabled("cancelWorkFlow");
  toolbar.enabled("editWorkFlow");
  toolbar.enabled("resend");
  toolbar.enabled("delete");
  toolbar.enabled("relationAuthority");
}

function cancelDate(dataRows) {
  var rows = typeof dataRows === "undefined" ? grid.grid.getSelectRows() : dataRows; //js事件接口

  var sendDevelop = $.ctp.trigger('beforeSentCancel');

  if (!sendDevelop) {
    return;
  }

  disabledToolbar();

  if (rows.length === 0) {
    //请选择需要撤销的公文！
    $.alert($.i18n('govdoc.listSent.selectRevokeSyn'));
    enabledToolbar();
    return;
  }

  if (rows.length > 1) {
    //只能选择一条记录!
    $.alert($.i18n('collaboration.listSent.selectOneData'));
    enabledToolbar();
    return;
  } //老公文 屏蔽该功能


  if (rows[0].app > 4) {
    $.alert("《" + rows[0].subject + "》 " + $.i18n('govdoc.oldData.document') + $.i18n('edoc.alert.oldEdocSummary.noFunction'));
    enabledToolbar();
    return;
  }

  var selRow = rows[0];
  var affairId = selRow.affairId;
  var summaryId = selRow.summaryId;
  var processId = selRow.processId; //校验开始

  var ajaxManager = new govdocAManager();
  var params = new Object();
  params["summaryId"] = summaryId; //校验是否流程结束、是否审核、是否核定，涉及到的子流程调用工作流接口校验

  var canDealCancel = ajaxManager.checkIsCanRepeal(params);

  if (canDealCancel.msg != null) {
    $.alert(canDealCancel.msg);
    enabledToolbar();
    return;
  }

  if (!isAffairValid(affairId)) {
    enabledToolbar();
    return;
  } //调用工作流接口校验是否能够撤销流程


  var appName = "collaboration";

  if (typeof rows[0].affairApp != 'undefined' && rows[0].affairApp == "4") {
    appName = "edoc";
  } //var repeal = canRepeal('collaboration',processId,'start');


  var repeal = canRepeal(appName, processId, 'start'); //不能撤销流程

  if (repeal[0] === 'false') {
    $.alert(repeal[1]);
    enabledToolbar();
    return;
  }

  var lockWorkflowRe = lockWorkflow(selRow.processId, $.ctx.CurrentUser.id, 12);

  if (lockWorkflowRe[0] == "false") {
    $.alert(lockWorkflowRe[1]);
    enabledToolbar();
    return;
  }

  if (!executeWorkflowBeforeEvent("BeforeCancel", summaryId, affairId, processId, processId, "", "", "")) {
    enabledToolbar();
    return;
  }

  var bottomHTML = '';
  bottomHTML += '<span">'; //bottomHTML += $.i18n("govdoc.workflow.trace.summary");

  bottomHTML += '</span>'; //撤销流程

  var dialog = $.dialog({
    url: _ctxPath + "/workflowmanage/workflowmanage.do?method=showRepealCommentDialog&affairId=" + affairId,
    width: 450,
    height: 240,
    bottomHTML: bottomHTML,
    title: $.i18n('common.toolbar.repeal.label'),
    //撤销流程
    targetWindow: getCtpTop(),
    buttons: [{
      text: $.i18n('common.button.ok.label'),
      //确定
      btnType: 1,
      handler: function handler() {
        enabledToolbar();
        var returnValue = dialog.getReturnValue();

        if (!returnValue) {
          return;
        }

        var ajaxSubmitFunc = function ajaxSubmitFunc() {
          var tempMap = new Object();
          tempMap.repealComment = returnValue[0];
          tempMap.summaryIdStr = summaryId;
          tempMap.affairIdStr = affairId;
          tempMap.isWFTrace = returnValue[1];
          ajaxManager.govdocTransRepal(tempMap, {
            success: function success(msg) {
              if (msg == null || msg == "") {
                $("#summary").attr("src", "");
                $(".slideDownBtn").trigger("click");
                var url = window.location.search;

                if ($("#tableContent").length > 0) {
                  $("#tableContent").ajaxgridLoad();
                } else {
                  $("#listSent").ajaxgridLoad();
                }
              } else {
                $.alert(msg);
              }

              releaseWorkflowByAction(selRow.processId, $.ctx.CurrentUser.id, 12); //撤销后关闭，子页面

              try {
                closeOpenMultyWindow(affairId);
              } catch (e) {}

              ;
            }
          });
        };

        ajaxSubmitFunc();
        dialog.close();
      }
    }, {
      text: $.i18n('common.button.cancel.label'),
      //取消
      handler: function handler() {
        enabledToolbar();
        releaseWorkflowByAction(selRow.processId, $.ctx.CurrentUser.id, 12);
        dialog.close();
      }
    }],
    closeParam: {
      show: true,
      handler: function handler() {
        enabledToolbar();
        releaseWorkflowByAction(selRow.processId, $.ctx.CurrentUser.id, 12);
      }
    }
  });
}

function deleteItems(pageType, gridI, tableId, from, inputRows) {
  if (!pageType || !page_types[pageType]) {
    $.alert('pageType is illegal:' + pageType);
    return true;
  }

  var rows = typeof inputRows === "undefined" ? gridI.grid.getSelectRows() : inputRows;
  var affairIds = "";

  if (rows.length <= 0) {
    // 请选择要删除的公文。
    $.alert($.i18n('govdoc.grid.selectDelete'));
    return true;
  }

  var obj;

  for (var i = 0; i < rows.length; i++) {
    obj = rows[i];

    try {
      closeOpenMultyWindow(obj.affairId, false);
    } catch (e) {}

    ; // 指定回退状态状态不能删除

    if (pageType == "draft") {
      if (obj.affairSubState == '16') {
        $.alert($.i18n('collaboration.alert.CantModifyBecauseOfAppointStepBack'));
        obj.checked = false;
        return true;
      }
    }

    if (pageType == "pending") {
      if (obj.templeteId) {
        // 未办理的模板协同不允许直接归档或删除!
        $.alert($.i18n('collaboration.template.notHandle.notDeleteArchive') + "<br><br>" + "&lt;" + obj.subject + ">");
        obj.checked = false;
        return true;
      }

      var lockWorkflowRe = checkWorkflowLock(obj.processId, $.ctx.CurrentUser.id, 14);

      if (lockWorkflowRe[0] == "false") {
        $.alert(lockWorkflowRe[1] + "<br><br>" + "<" + obj.subject + ">");
        obj.checked = false;
        return true;
      } // 以下事项要求意见不能为空，不能直接归档或删除:


      if (!obj.canDeleteORarchive) {
        $.alert($.i18n('collaboration.template.notDeleteArchive.nullOpinion') + "<br><br>" + "<" + obj.subject + ">");
        obj.checked = false;
        return true;
      } // 指定回退时不能处理


      var canSubmitWorkFlowRe = canSubmitWorkFlow(obj.workitemId);

      if (canSubmitWorkFlowRe[0] == "false") {
        $.alert(canSubmitWorkFlowRe[1]);
        check = true;
        return false;
      }
    }
  } // end


  var confirm = $.confirm({
    // 该操作不能恢复，是否进行删除操作
    'msg': $.i18n('edoc.deleteconfirm.alert.label'),
    ok_fn: function ok_fn() {
      for (var count = 0; count < rows.length; count++) {
        if (count == rows.length - 1) {
          affairIds += rows[count].affairId;
        } else {
          affairIds += rows[count].affairId + "*";
        }
      } // table提交


      var callerResponder = new CallerResponder(); // 实例化Spring BS对象

      var ajaxManager = new govdocAManager();
      var param = new Object();
      param["pageType"] = pageType;
      param["affairIds"] = affairIds;
      param["fromMethod"] = from;
      ajaxManager.checkCanDelete(param, {
        success: function success(flag) {
          if ("success" == flag) {
            // 循环删除，隔离后台的事务，否则多个流程事务一起提交工作流部分的数据可能会出错
            var ids = affairIds.split("*");

            for (var i = 0; i < ids.length; i++) {
              ajaxManager.deleteAffair(pageType, ids[i]);
            } //关闭已经删除了事项打开的子页面


            for (var i = 0; i < ids.length; i++) {
              try {
                closeOpenMultyWindow(ids[i], false);
              } catch (e) {}
            } // 成功删除，并刷新列表


            $.messageBox({
              'title': $.i18n('common.system.hint.label'),
              'type': 0,
              'msg': $.i18n('common.delete.success.label'),
              'imgType': 0,
              ok_fn: function ok_fn() {
                var totalNum = gridI.p.total - 1;
                $('#summary').attr("src", "govdoc.do?method=listDesc&type=" + tableId + "&size=" + totalNum);
                $("#" + tableId).ajaxgridLoad();
              }
            });
          } else {
            $.alert(flag);
          }
        },
        error: function error(request, settings, e) {
          $.alert(e);
        }
      });
    }
  });
} //向指定对象封装参数


function setParamsToObject(o, url) {
  if (!o.app && url.indexOf('app') != -1) {
    o.app = GetQueryString(url, "app");
  }

  if (!o.sub_app && url.indexOf('sub_app') != -1) {
    o.sub_app = GetQueryString(url, "sub_app");
  }

  if (!o.finishstate && url.indexOf('finishstate') != -1) {
    o.finishstate = GetQueryString(url, "finishstate");
  }

  if (!o.listCfgId && url.indexOf('listCfgId') != -1) {
    o.listCfgId = GetQueryString(url, "listCfgId");
  }

  if (!o.subState && url.indexOf('subState') != -1) {
    o.subState = GetQueryString(url, "subState");
  }

  if (!o.listType && url.indexOf('listType') != -1) {
    o.listType = GetQueryString(url, "listType");
  }

  if (!o.govdocType && url.indexOf('govdocType') != -1) {
    o.govdocType = GetQueryString(url, "govdocType");
  }

  if (!o.resourceId && url.indexOf('resourceId') != -1) {
    o.resourceId = GetQueryString(url, "resourceId");
  }

  var sfrom = GetQueryString(url, "sfrom");

  if (typeof sfrom != 'undefined') {
    o.sfrom = sfrom;
  }

  var srcFrom = GetQueryString(url, "srcFrom");

  if (srcFrom && srcFrom == "bizconfig") {
    if (_paramTemplateIds && _paramTemplateIds != null && _paramTemplateIds != "") {
      o.templeteIds = $.trim(_paramTemplateIds);
    }
  }
} //获取指定url里面参数的值，没有则返回空


function GetQueryString(url, name) {
  if (null == name || "" == name || undefined == name || null == url || "" == url || undefined == url) {
    return null;
  }

  var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  var r = url.substr(1).match(reg);
  if (r != null) return unescape(r[2]);
  return null;
} //转公告


function dealTransmitBulletinFunc(_x, _x2) {
  return _dealTransmitBulletinFunc.apply(this, arguments);
} //转办


function _dealTransmitBulletinFunc() {
  _dealTransmitBulletinFunc = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(event, rowDatas) {
    var rows, summaryId, canTrans, ajaxManager, operation, retval, content, transFileId, bodyType, isUseWeboffice, r, requestCaller, rs, type, bulletinIssueBack, confirm;
    return regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;

            if (!(rows.length === 0)) {
              _context.next = 4;
              break;
            }

            $.alert($.i18n("govdoc.alert.bulletin.not.choose"));
            return _context.abrupt("return");

          case 4:
            if (!(rows.length > 1)) {
              _context.next = 7;
              break;
            }

            //只能选择一项协同进行取回!
            $.alert($.i18n("govdoc.alert.bulletin.more.choose"));
            return _context.abrupt("return");

          case 7:
            if (!(rows[0].affairSubApp > 4)) {
              _context.next = 10;
              break;
            }

            $.alert("《" + rows[0].subject + "》 " + $.i18n('govdoc.oldData.document') + $.i18n('edoc.alert.oldEdocSummary.noFunction'));
            return _context.abrupt("return");

          case 10:
            summaryId = rows[0].summaryId;
            canTrans = callBackendMethod("secretAjaxManager", "canTransSecretLevel", summaryId);

            if (!(canTrans == false)) {
              _context.next = 15;
              break;
            }

            $.alert($.i18n('govdoc.grid.alert.noTransSecretData'));
            return _context.abrupt("return");

          case 15:
            ajaxManager = new govdocAManager();
            operation = "TransmitBulletin";
            retval = ajaxManager.hasTransCollStrategy(rows[0].orgAccountId, rows[0].govdocType, rows[0].affairId, operation);

            if (!(retval != operation)) {
              _context.next = 21;
              break;
            }

            $.alert($.i18n("govdoc.alert.bulletin.not.operation"));
            return _context.abrupt("return");

          case 21:
            if (!((rows[0].govdocType == "2" || rows[0].govdocType == "4") && checkSummaryPrintControl(summaryId))) {
              _context.next = 24;
              break;
            }

            $.alert($.i18n("govdoc.print.control.prompt2")); // 该正文打印受控制，不支持转公告操作

            return _context.abrupt("return");

          case 24:
            content = ajaxManager.getFirstContentType(summaryId); // 转版之后的转版ID

            transFileId = "";
            bodyType = content.bodyType;

            if (!(bodyType == '')) {
              _context.next = 30;
              break;
            }

            $.alert($.i18n("govdoc.alert.system.error"));
            return _context.abrupt("return");

          case 30:
            // 转公告支持转版的OFD和PDF
            if ('Pdf' == bodyType || bodyType == 'Ofd') {
              transFileId = content.pdfId;
            }

            _context.next = 33;
            return getIsUseWeboffice();

          case 33:
            isUseWeboffice = _context.sent;

            //如果使用weboffice编辑情况下，并且正文类型为word
            if (!(isUseWeboffice && (bodyType == "OfficeWord" || bodyType == "WpsWord"))) {
              bodyType = "HTML";
            } //列表判断是否有转公告权限


            if (!(typeof govdocAManager != "undefined")) {
              _context.next = 41;
              break;
            }

            ajaxManager = new govdocAManager();
            r = ajaxManager.getRightByAction(rows[0].affairId, "TransmitBulletin");

            if (!(r && r != true)) {
              _context.next = 41;
              break;
            }

            $.alert(r);
            return _context.abrupt("return");

          case 41:
            //Ajax判断是否有发布新闻、公告的权限
            requestCaller = new XMLHttpRequestCaller(this, "edocManager", "AjaxjudgeHasPermitIssueNewsOrBull", false);
            requestCaller.addParameter(1, "String", 'bulletionaudit');
            rs = requestCaller.serviceRequest();

            if (!(rs == "false")) {
              _context.next = 47;
              break;
            }

            $.alert($.i18n("govdoc.trans.dontHavePublishRigths.label"));
            return _context.abrupt("return");

          case 47:
            type = "govdoc";

            bulletinIssueBack = function bulletinIssueBack(rv) {
              if (rv) {
                $.infor($.i18n("govdoc.transfer.announcement"));
              } //alert(v3x.getMessage("edocLang.edoc_transferred_announcement"));

            }; //word类型的公告需要提示清稿


            if (bodyType == "OfficeWord" || bodyType == "WpsWord") {
              confirm = $.confirm({
                'msg': $.i18n("govdoc.transBulletin.clearAllTraces.label"),
                ok_fn: function ok_fn() {
                  confirm.close();
                  edocBulletinIssue(summaryId, transFileId, bodyType, bulletinIssueBack, rows[0].affairSubject);
                },
                cancel_fn: function cancel_fn() {
                  confirm.close();
                }
              });
            } else {
              edocBulletinIssue(summaryId, transFileId, bodyType, bulletinIssueBack, rows[0].affairSubject);
            }

          case 50:
          case "end":
            return _context.stop();
        }
      }
    }, _callee, this);
  }));
  return _dealTransmitBulletinFunc.apply(this, arguments);
}

function turnToRec(event, rowDatas) {
  var rows = typeof rowDatas === "undefined" ? grid.grid.getSelectRows() : rowDatas;

  if (rows.length === 0) {
    $.alert($.i18n("govdoc.alert.turnToRec.not.choose"));
    return;
  }

  if (rows.length > 1) {
    //只能选择一项协同进行取回!
    $.alert($.i18n("govdoc.alert.turnToRec.more.choose"));
    return;
  }

  if (checkGovdocDeviceSecret(rows[0])) {
    return;
  } //老公文 屏蔽该功能


  if (rows[0].affairSubApp > 4) {
    $.alert("《" + rows[0].subject + "》 " + $.i18n('govdoc.oldData.document') + $.i18n('edoc.alert.oldEdocSummary.noFunction'));
    return;
  }

  var summaryId = rows[0].summaryId;
  var govdType = rows[0].govdocType;
  var affId = rows[0].affairId;

  if (govdType != 2) {
    $.alert($.i18n("govdoc.alert.turnToRec.only.rec"));
    return;
  }

  var operation = "TurnRecEdoc";
  var ajaxManager = new govdocAManager();
  var retval = ajaxManager.hasTransCollStrategy(rows[0].orgAccountId, rows[0].govdocType, rows[0].affairId, operation);

  if (retval != operation) {
    $.alert($.i18n("govdoc.alert.turnToRec.not.operation"));
    return;
  }

  var orgRanges = ajaxManager.getOrgRangeBySummaryId(summaryId);
  var par = new Object();
  par.dan = "1";
  $.selectPeople({
    panels: 'OcipOrganization,Account,Department,OrgTeam,OrgMetadataTag',
    selectType: 'Account,Department,OrgTeam,OrgMetadataTag',
    hiddenPostOfDepartment: true,
    isNeedCheckLevelScope: false,
    showAllOuterDepartment: true,
    isAllowContainsChildDept: true,
    params: par,
    minSize: 0,
    excludeElements: orgRanges,
    callback: function callback(ret) {
      var turnToRecClickCount = 0; //转办确定 重复点击计数

      var dialog = $.dialog({
        id: "turnRecEdoc",
        height: "400",
        width: "400",
        transParams: {
          selectVal: ret.value,
          selectText: ret.text
        },
        url: _ctxPath + '/govdoc/govdoc.do?method=toTurnRecEdoc&summaryId=' + summaryId,
        title: $.i18n('permission.operation.TurnRecEdoc'),
        buttons: [{
          id: "okButton",
          text: $.i18n("common.button.ok.label"),
          btnType: 1,
          handler: function handler() {
            turnToRecClickCount++;

            if (turnToRecClickCount > 1) {
              $.alert($.i18n("govdoc.repeat.click.doNot")); //请不要重复点击

              return;
            }

            var rv = dialog.getReturnValue();

            if (rv == null) {
              $.alert($.i18n('govdoc.turnRecEdoc.noAccount.label'));
              return;
            }

            if (rv.opinion.length > 1000) {
              $.alert($.i18n('govdoc.turnRecEdoc.moreThanWords.label'));
              return;
            }

            var selectUnitId = rv.selectUnitId;

            var checkRoleCallback = function checkRoleCallback() {
              var result = ajaxManager.verifyUnitExists(selectUnitId, summaryId);

              if (result != null) {
                var num = 0;
                var confirm = $.confirm({
                  'msg': $.i18n('govdoc.turnRecEdoc.sendMessage.label', result.names),
                  ok_fn: function ok_fn() {
                    num++;

                    if (num > 1) {
                      $.alert($.i18n("govdoc.repeat.click.doNot")); //请不要重复点击
                    }

                    var timestamp = new Date().valueOf();
                    $.ajax({
                      url: _ctxPath + '/govdoc/govdoc.do?method=doTurnRecEdoc&timestamp=' + timestamp,
                      type: "post",
                      data: {
                        affairId: affId,
                        unitId: selectUnitId,
                        opinion: rv.opinion
                      },
                      success: function success(data) {
                        $.infor({
                          msg: $.i18n('govdoc.turnRecEdoc.transferred.label'),
                          ok_fn: function ok_fn() {
                            if (event && event.successCallback) {
                              event.successCallback();
                            }
                          },
                          close_fn: function close_fn() {
                            if (event && event.successCallback) {
                              event.successCallback();
                            }
                          }
                        });
                        dialog.close();
                      }
                    });
                  },
                  cancel_fn: function cancel_fn() {
                    selectUnitId = result.finalIds;

                    if (selectUnitId == "") {
                      $.alert($.i18n('govdoc.turnRecEdoc.noAccount.label'));
                      return;
                    }

                    var timestamp = new Date().valueOf();
                    $.ajax({
                      url: _ctxPath + '/govdoc/govdoc.do?method=doTurnRecEdoc&timestamp=' + timestamp,
                      type: "post",
                      data: {
                        affairId: affId,
                        unitId: selectUnitId,
                        opinion: rv.opinion
                      },
                      success: function success(data) {
                        $.infor({
                          msg: $.i18n('govdoc.turnRecEdoc.transferred.label'),
                          ok_fn: function ok_fn() {
                            if (event && event.successCallback) {
                              event.successCallback();
                            }
                          },
                          close_fn: function close_fn() {
                            if (event && event.successCallback) {
                              event.successCallback();
                            }
                          }
                        });
                        dialog.close();
                      }
                    });
                  },
                  close_fn: function close_fn() {
                    confirm.close();
                  }
                });
              } else {
                var timestamp = new Date().valueOf();
                $.ajax({
                  url: _ctxPath + '/govdoc/govdoc.do?method=doTurnRecEdoc&timestamp=' + timestamp,
                  type: "post",
                  data: {
                    affairId: affId,
                    unitId: selectUnitId,
                    opinion: rv.opinion
                  },
                  success: function success(data) {
                    turnToRecClickCount = 0;
                    var ajaxManager = new govdocAManager();
                    var returnVal = ajaxManager.validateExistAccount(selectUnitId);

                    if (returnVal && returnVal != "") {
                      $.alert($.i18n('govdoc.turnRecEdoc.noSucceed.label') + returnVal);
                    } else {
                      $.infor({
                        msg: $.i18n('govdoc.turnRecEdoc.transferred.label'),
                        ok_fn: function ok_fn() {
                          if (event && event.successCallback) {
                            event.successCallback();
                          }
                        },
                        close_fn: function close_fn() {
                          if (event && event.successCallback) {
                            event.successCallback();
                          }
                        }
                      });
                    }

                    dialog.close();
                  }
                });
              }
            };

            var msg = ajaxManager.checkExchangeRole(selectUnitId);

            if ("ok" != msg) {
              var con = $.messageBox({
                'imgType': '4',
                'type': 100,
                'msg': $.i18n('govdoc.error.send.no.gwsfy.tips', msg),
                buttons: [{
                  id: 'btn1',
                  text: $.i18n('govdoc.turnRecEdoc.continue.send.label'),
                  handler: function handler() {
                    checkRoleCallback();
                    con.close();
                  }
                }, {
                  id: 'btn2',
                  text: $.i18n('govdoc.turnRecEdoc.suspend.send.label'),
                  handler: function handler() {
                    con.close();
                  }
                }],
                close_fn: function close_fn() {}
              });
            } else {
              checkRoleCallback();
            }
          }
        }, {
          id: "cancelButton",
          text: $.i18n("common.button.cancel.label"),
          handler: function handler() {
            dialog.close();
          }
        }]
      });
    }
  });
} //批处理


function batchEdoc(event, row) {
  var rows = typeof row == "undefined" ? grid.grid.getSelectRows() : [row];

  if (rows.length == 0) {
    $.alert($.i18n('collaboration.listPending.selectBatchData')); //请选择要删除的记录

    return;
  }
  /*    var sendDevelop = $.ctp.trigger('beforeBatchDealColl');
         if(!sendDevelop){
             return;
         }*/


  var process = new BatchProcess();

  for (var i = 0; i < rows.length; i++) {
    var affairId = rows[i].affairId;
    var subject = rows[i].subject;
    var category = rows[i].affairApp || "4";
    var summaryId = rows[i].summaryId;

    if (process.batchOpinion == "0" || process.batchOpinion == null) {
      process.batchOpinion = rows[i].disAgreeOpinionPolicy == null ? "0" : rows[i].disAgreeOpinionPolicy == "1" ? "3" : "0"; //意见是否必填，3,不同意时，意见必填
    }

    process.addData(affairId, summaryId, category, subject);
  }

  if (!process.isEmpty()) {
    var r = process.doBatch();
  }
  /*  if(!rows.length == 0){
       $.alert($.i18n("edocLang.batch_select_affair"));
       return ;
     }
     var process = new BatchProcess();
     for(var i = 0 ; i < checkBoxs.length;i++){
       if(rows[i].checked){
         var affairId = rows[i].getAttribute("affairId");
     var subject = rows[i].getAttribute("subject");
     var app = "4";
         process.addData(affairId,checkBoxs[i].value,app,subject);
       }
     }
     if(!process.isEmpty()){
       var r = process.doBatch("getA8Top().contentFrame.topFrame.refreshWorkspace()");
     }else{
       $.alert($.i18n("edocLang.batch_select_affair"));
       return ;
     }*/

}
/**
 * 是否开启了weboffice在线编辑
 */


function getIsUseWeboffice() {
  return _getIsUseWeboffice.apply(this, arguments);
}
/**
 * 转办记录打开
 * @param summaryId
 * @returns
 */


function _getIsUseWeboffice() {
  _getIsUseWeboffice = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
    var xhrFun;
    return regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            xhrFun = $.ajax ? $.ajax : window.top.jQuery.ajax;
            return _context2.abrupt("return", new Promise(function (resolve, reject) {
              xhrFun({
                url: _ctxPath + '/rest/webOffice/checkWebOfficeEnable',
                async: false,
                method: "get",
                dataType: 'json',
                success: function success(res) {
                  if (res.code == 0 && res.data) {
                    xhrFun({
                      url: _ctxPath + '/rest/officePlugins/personal/settings?useWpspro=0&_rand=' + new Date().getTime(),
                      async: false,
                      method: "get",
                      dataType: 'json',
                      success: function success(res) {
                        if (res.code == 0) {
                          var useWebOffice = res.data.usePersonal == '1';
                          window.top.isUseWeboffice = useWebOffice;
                          resolve(useWebOffice);
                        } else {
                          resolve(false);
                        }
                      },
                      error: function error(err) {
                        console.error(err);
                        resolve(false);
                      }
                    });
                  } else {
                    resolve(false);
                  }
                },
                error: function error(err) {
                  console.error(err);
                  resolve(false);
                }
              });
            }));

          case 2:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _getIsUseWeboffice.apply(this, arguments);
}

function showTurnRecEdocInfo(summaryId) {
  var dialog = $.dialog({
    id: "showTurnRecEdocInfo",
    height: "400",
    width: "800",
    url: _ctxPath + "/govdoc/exchange.do?method=showExchangeSendState&exchangeType=2&summaryId=" + summaryId,
    title: $.i18n("govdoc.sendGrid.turnRecEdoc"),
    buttons: [{
      id: "okButton",
      text: $.i18n("common.button.ok.label"),
      btnType: 1,
      handler: function handler() {
        dialog.close();
      }
    }]
  });
}
/**
 * 根据公文ID校验该文OFD正文是否进行了打印控制
 * @param summaryId 公文ID
 * @returns {*} true-控制 | false-未控制
 */


function checkSummaryPrintControl(summaryId) {
  return callBackendMethod("govdocRecievePrintControlManager", "checkSummaryPrintControl", summaryId);
}
/**
 * 根据summaryId判定当前文件密级是否低于设备密级
 *
 * @param data 列表行数据 row
 *        showTitle 提示语是否显示标题
 * @returns {boolean} true 表示 低于设备密级，校验不通过
 */


function checkGovdocDeviceSecret(data, showTitle) {
  // 老公文不参与校验
  if (data.affairSubApp > 4) {
    return false;
  }

  var msg = callBackendMethod("govdocAManager", "checkGovdocDeviceSecret", data.summaryId);

  if (msg == 'ok') {
    return false;
  } else {
    if (showTitle) {
      $.alert(msg + "<br><br>" + "《" + data.subject + "》");
    } else {
      $.alert(msg);
    }

    return true;
  }
}